import json

from devicetest.api import Asserts
from devicetest.aw.OpenHarmony import CommonOH
from devicetest.core.test_case import TestCase, Step

from aw.common import common_setup, common_teardown
from aw.pom import Setting, DeskTop


class PreTest_RK3568_Basic_Setting_5600(TestCase, Setting):
    # 预置条件：
    # 烧写目标版本后，正常进入桌面-设置-系统
    # 测试步骤：
    # 1.点击软件更新
    # 2.点击检查更新
    # 预期结果：
    # 1.进入软件更新
    # 2.界面有OpenHarmony检查更新动画，可更新至最新版本

    def __init__(self, controllers):
        self.TAG = self.__class__.__name__
        TestCase.__init__(self, self.TAG, controllers)

    def setup(self):
        common_setup(self.Phone1)

    def process(self):
        Step('步骤1：烧写目标版本后，正常进入桌面-设置-系统,点击软件更新')
        CommonOH.startAbility(self.Phone1, self.ability_name, self.bundle_name)
        CommonOH.wait(self.Phone1, 1)
        CommonOH.swipe(self.Phone1, **DeskTop.swipe_up)
        CommonOH.wait(self.Phone1, 3)
        CommonOH.touchByText(self.Phone1, '系统')
        CommonOH.touchByText(self.Phone1, '软件更新')
        CommonOH.wait(self.Phone1, 5)
        Step('预期结果1：进入软件更新')
        CommonOH.checkIfTextExist(self.Phone1, '检查更新')

        Step('步骤2：点击检查更新')
        CommonOH.touchByText(self.Phone1, '检查更新')
        Step('预期结果2: 界面有OpenHarmony检查更新动画，可更新至最新版本')
        CommonOH.wait(self.Phone1, 5)
        CommonOH.touchByText(self.Phone1, '已是最新版本')

    def teardown(self):
        common_teardown(self.Phone1, self.bundle_name)
